﻿using famails.bus;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace famails
{
    public partial class tintuc_detail : System.Web.UI.Page
    {
        static public ArticleBUS bus = new ArticleBUS();
        public GroupBUS bus_group = new GroupBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable topRead = bus.GetTop1Read();
                if (topRead != null && topRead.Rows.Count > 0)
                {
                    imgTopRead.ImageUrl = topRead.Rows[0]["image"] + "";
                    lblTopRead.Text = topRead.Rows[0]["title"] + "";
                    lblTopRead1.NavigateUrl = lblTopRead.NavigateUrl = "tintuc_detail.aspx?id=" + topRead.Rows[0]["articleid"];
                }
                int id = 0;
                int.TryParse(Request.QueryString["id"] + "", out id);
                DataTable detail = bus.GetByID(id);
                if (detail != null && detail.Rows.Count > 0)
                {
                    //imgNewest.ImageUrl = detail.Rows[0]["image"] + "";
                    lblTitle.Text = detail.Rows[0]["title"] + "";
                    lblCreatDate.Text = Convert.ToDateTime(detail.Rows[0]["CreateDate"] + "").ToString("'Ngày đăng : 'dd/MM/yyyy' - 'HH:mm");
                    //lblSummary.Text = detail.Rows[0]["Summary"] + "";
                    lblContent.Text = detail.Rows[0]["Content"] + "";

                    int categoryid = Convert.ToInt32(detail.Rows[0]["categoryid"]);
                    DataTable source = bus_group.GetAll("", 1, categoryid);
                    rptGroup.DataSource = source;
                    rptGroup.DataBind();
                }
                else{
                    lblContent.Text = "Bài viết không tồn tại!";
                }
                if (id > 0)
                    bus.ViewCount(id);
            }
        }
    }
}